const jwt = require("jsonwebtoken")
module.exports = options => {
    return async function auth(ctx, next) {
        const { authorization } = ctx.request.headers
        if (authorization) {
            try {
                const token = authorization.split(`Bearer `)[1]
                jwt.verify(token, '1901B')
                try {
                    await next()
                } catch (error) {
                    ctx.body = error
                }
            } catch (error) {
                ctx.body = {
                    code: 0,
                    msg: "登录失效，请重新登录"
                }
            }
        } else {
            ctx.body = {
                code: 0,
                msg: "未登录"
            }
        }
    }
}